

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>mindspore.nn.probability.distribution.Gamma &mdash; MindSpore master documentation</title>
  

  
  <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/language_data.js"></script>
        <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="mindspore.nn.probability.distribution.Geometric" href="mindspore.nn.probability.distribution.Geometric.html" />
    <link rel="prev" title="mindspore.nn.probability.distribution.Exponential" href="mindspore.nn.probability.distribution.Exponential.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../index.html" class="icon icon-home"> MindSpore
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">MindSpore Python API</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../mindspore.html">mindspore</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.common.initializer.html">mindspore.common.initializer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.communication.html">mindspore.communication</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.compression.html">mindspore.compression</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.context.html">mindspore.context</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.html">mindspore.dataset</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.audio.html">mindspore.dataset.audio</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.config.html">mindspore.dataset.config</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.text.html">mindspore.dataset.text</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.transforms.html">mindspore.dataset.transforms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.vision.html">mindspore.dataset.vision</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.mindrecord.html">mindspore.mindrecord</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.nn.html">mindspore.nn</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../mindspore.nn.probability.html">mindspore.nn.probability</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.probability.html#bijectors">Bijectors</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../mindspore.nn.probability.html#distributions">Distributions</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.probability.distribution.Bernoulli.html">mindspore.nn.probability.distribution.Bernoulli</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.probability.distribution.Beta.html">mindspore.nn.probability.distribution.Beta</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.probability.distribution.Categorical.html">mindspore.nn.probability.distribution.Categorical</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.probability.distribution.Cauchy.html">mindspore.nn.probability.distribution.Cauchy</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.probability.distribution.Distribution.html">mindspore.nn.probability.distribution.Distribution</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.probability.distribution.Exponential.html">mindspore.nn.probability.distribution.Exponential</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">mindspore.nn.probability.distribution.Gamma</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.probability.distribution.Geometric.html">mindspore.nn.probability.distribution.Geometric</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.probability.distribution.Gumbel.html">mindspore.nn.probability.distribution.Gumbel</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.probability.distribution.Logistic.html">mindspore.nn.probability.distribution.Logistic</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.probability.distribution.LogNormal.html">mindspore.nn.probability.distribution.LogNormal</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.probability.distribution.Normal.html">mindspore.nn.probability.distribution.Normal</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.probability.distribution.Poisson.html">mindspore.nn.probability.distribution.Poisson</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.probability.distribution.TransformedDistribution.html">mindspore.nn.probability.distribution.TransformedDistribution</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.probability.distribution.Uniform.html">mindspore.nn.probability.distribution.Uniform</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.nn.transformer.html">mindspore.nn.transformer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.numpy.html">mindspore.numpy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.ops.html">mindspore.ops</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.parallel.html">mindspore.parallel</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.parallel.nn.html">mindspore.parallel.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.profiler.html">mindspore.profiler</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.scipy.html">mindspore.scipy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.train.html">mindspore.train</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.boost.html">mindspore.boost</a></li>
</ul>
<p class="caption"><span class="caption-text">MindSpore C++ API</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html">MindSpore Lite↗</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">MindSpore</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../index.html" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../mindspore.nn.probability.html">mindspore.nn.probability</a> &raquo;</li>
        
      <li>mindspore.nn.probability.distribution.Gamma</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../../_sources/api_python/nn_probability/mindspore.nn.probability.distribution.Gamma.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="mindspore-nn-probability-distribution-gamma">
<h1>mindspore.nn.probability.distribution.Gamma<a class="headerlink" href="#mindspore-nn-probability-distribution-gamma" title="Permalink to this headline">¶</a></h1>
<dl class="class">
<dt id="mindspore.nn.probability.distribution.Gamma">
<em class="property">class </em><code class="sig-prename descclassname">mindspore.nn.probability.distribution.</code><code class="sig-name descname">Gamma</code><span class="sig-paren">(</span><em class="sig-param">concentration=None</em>, <em class="sig-param">rate=None</em>, <em class="sig-param">seed=None</em>, <em class="sig-param">dtype=mstype.float32</em>, <em class="sig-param">name='Gamma'</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.nn.probability.distribution.Gamma" title="Permalink to this definition">¶</a></dt>
<dd><p>伽马分布（Gamma distribution）。
连续随机分布，取值范围为 <span class="math notranslate nohighlight">\((0, \inf)\)</span> ，概率密度函数为</p>
<div class="math notranslate nohighlight">
\[f(x, \alpha, \beta) = \beta^\alpha / \Gamma(\alpha) x^{\alpha - 1} \exp(-\beta x).\]</div>
<p>其中 <span class="math notranslate nohighlight">\(G\)</span> 为 Gamma 函数。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>concentration</strong> (int, float, list, numpy.ndarray, Tensor) - 浓度，也被称为伽马分布的alpha。默认值：None。</p></li>
<li><p><strong>rate</strong> (int, float, list, numpy.ndarray, Tensor) - 逆尺度参数，也被称为伽马分布的beta。默认值：None。</p></li>
<li><p><strong>seed</strong> (int) - 采样时使用的种子。如果为None，则使用全局种子。默认值：None。</p></li>
<li><p><strong>dtype</strong> (mindspore.dtype) - 事件样例的类型。默认值：mindspore.float32。</p></li>
<li><p><strong>name</strong> (str) - 分布的名称。默认值：’Gamma’。</p></li>
</ul>
<div class="admonition note">
<p class="admonition-title">Note</p>
<ul class="simple">
<li><p><cite>concentration</cite> 和 <cite>rate</cite> 中的元素必须大于零。</p></li>
<li><p><cite>dtype</cite> 必须是float，因为伽马分布是连续的。</p></li>
</ul>
</div>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>ValueError</strong> - <cite>concentration</cite> 或者 <cite>rate</cite> 中元素小于0。</p></li>
<li><p><strong>TypeError</strong> - <cite>dtype</cite> 不是float的子类。</p></li>
</ul>
<p><strong>支持平台：</strong></p>
<p><code class="docutils literal notranslate"><span class="pre">Ascend</span></code></p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">mindspore</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">mindspore.nn</span> <span class="k">as</span> <span class="nn">nn</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">mindspore.nn.probability.distribution</span> <span class="k">as</span> <span class="nn">msd</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">mindspore</span> <span class="kn">import</span> <span class="n">Tensor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># To initialize a Gamma distribution of the concentration 3.0 and the rate 4.0.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g1</span> <span class="o">=</span> <span class="n">msd</span><span class="o">.</span><span class="n">Gamma</span><span class="p">([</span><span class="mf">3.0</span><span class="p">],</span> <span class="p">[</span><span class="mf">4.0</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="n">mindspore</span><span class="o">.</span><span class="n">float32</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># A Gamma distribution can be initialized without arguments.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># In this case, `concentration` and `rate` must be passed in through arguments.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g2</span> <span class="o">=</span> <span class="n">msd</span><span class="o">.</span><span class="n">Gamma</span><span class="p">(</span><span class="n">dtype</span><span class="o">=</span><span class="n">mindspore</span><span class="o">.</span><span class="n">float32</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Here are some tensors used below for testing</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">value</span> <span class="o">=</span> <span class="n">Tensor</span><span class="p">([</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">,</span> <span class="mf">3.0</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="n">mindspore</span><span class="o">.</span><span class="n">float32</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">concentration_a</span> <span class="o">=</span> <span class="n">Tensor</span><span class="p">([</span><span class="mf">2.0</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="n">mindspore</span><span class="o">.</span><span class="n">float32</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rate_a</span> <span class="o">=</span> <span class="n">Tensor</span><span class="p">([</span><span class="mf">2.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="n">mindspore</span><span class="o">.</span><span class="n">float32</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">concentration_b</span> <span class="o">=</span> <span class="n">Tensor</span><span class="p">([</span><span class="mf">1.0</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="n">mindspore</span><span class="o">.</span><span class="n">float32</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rate_b</span> <span class="o">=</span> <span class="n">Tensor</span><span class="p">([</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">1.5</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="n">mindspore</span><span class="o">.</span><span class="n">float32</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Private interfaces of probability functions corresponding to public interfaces, including</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># `prob`, `log_prob`, `cdf`, `log_cdf`, `survival_function`, and `log_survival`,</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># have the same arguments as follows.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Args:</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#     value (Tensor): the value to be evaluated.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#     concentration (Tensor): the concentration of the distribution. Default: self._concentration.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#     rate (Tensor): the rate of the distribution. Default: self._rate.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Examples of `prob`.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Similar calls can be made to other probability functions</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># by replacing &#39;prob&#39; by the name of the function</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ans</span> <span class="o">=</span> <span class="n">g1</span><span class="o">.</span><span class="n">prob</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">ans</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>
<span class="go">(3,)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Evaluate with respect to the distribution b.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ans</span> <span class="o">=</span> <span class="n">g1</span><span class="o">.</span><span class="n">prob</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">concentration_b</span><span class="p">,</span> <span class="n">rate_b</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">ans</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>
<span class="go">(3,)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># `concentration` and `rate` must be passed in during function calls for g2.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ans</span> <span class="o">=</span> <span class="n">g2</span><span class="o">.</span><span class="n">prob</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">concentration_a</span><span class="p">,</span> <span class="n">rate_a</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">ans</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>
<span class="go">(3,)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Functions `mean`, `sd`, `mode`, `var`, and `entropy` have the same arguments.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Args:</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#     concentration (Tensor): the concentration of the distribution. Default: self._concentration.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#     rate (Tensor): the rate of the distribution. Default: self._rate.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Example of `mean`, `sd`, `mode`, `var`, and `entropy` are similar.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ans</span> <span class="o">=</span> <span class="n">g1</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">ans</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>
<span class="go">(1,)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ans</span> <span class="o">=</span> <span class="n">g1</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">concentration_b</span><span class="p">,</span> <span class="n">rate_b</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">ans</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>
<span class="go">(3,)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># `concentration` and `rate` must be passed in during function calls.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ans</span> <span class="o">=</span> <span class="n">g2</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">concentration_a</span><span class="p">,</span> <span class="n">rate_a</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">ans</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>
<span class="go">(3,)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Interfaces of &#39;kl_loss&#39; and &#39;cross_entropy&#39; are the same:</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Args:</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#     dist (str): the type of the distributions. Only &quot;Gamma&quot; is supported.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#     concentration_b (Tensor): the concentration of distribution b.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#     rate_b (Tensor): the rate of distribution b.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#     concentration_a (Tensor): the concentration of distribution a. Default: self._concentration.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#     rate_a (Tensor): the rate of distribution a. Default: self._rate.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Examples of `kl_loss`. `cross_entropy` is similar.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ans</span> <span class="o">=</span> <span class="n">g1</span><span class="o">.</span><span class="n">kl_loss</span><span class="p">(</span><span class="s1">&#39;Gamma&#39;</span><span class="p">,</span> <span class="n">concentration_b</span><span class="p">,</span> <span class="n">rate_b</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">ans</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>
<span class="go">(3,)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ans</span> <span class="o">=</span> <span class="n">g1</span><span class="o">.</span><span class="n">kl_loss</span><span class="p">(</span><span class="s1">&#39;Gamma&#39;</span><span class="p">,</span> <span class="n">concentration_b</span><span class="p">,</span> <span class="n">rate_b</span><span class="p">,</span> <span class="n">concentration_a</span><span class="p">,</span> <span class="n">rate_a</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">ans</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>
<span class="go">(3,)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Additional `concentration` and `rate` must be passed in.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ans</span> <span class="o">=</span> <span class="n">g2</span><span class="o">.</span><span class="n">kl_loss</span><span class="p">(</span><span class="s1">&#39;Gamma&#39;</span><span class="p">,</span> <span class="n">concentration_b</span><span class="p">,</span> <span class="n">rate_b</span><span class="p">,</span> <span class="n">concentration_a</span><span class="p">,</span> <span class="n">rate_a</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">ans</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>
<span class="go">(3,)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Examples of `sample`.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Args:</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#     shape (tuple): the shape of the sample. Default: ()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#     concentration (Tensor): the concentration of the distribution. Default: self._concentration.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#     rate (Tensor): the rate of the distribution. Default: self._rate.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ans</span> <span class="o">=</span> <span class="n">g1</span><span class="o">.</span><span class="n">sample</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">ans</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>
<span class="go">(1,)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ans</span> <span class="o">=</span> <span class="n">g1</span><span class="o">.</span><span class="n">sample</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">ans</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>
<span class="go">(2, 3, 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ans</span> <span class="o">=</span> <span class="n">g1</span><span class="o">.</span><span class="n">sample</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">),</span> <span class="n">concentration_b</span><span class="p">,</span> <span class="n">rate_b</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">ans</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>
<span class="go">(2, 3, 3)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ans</span> <span class="o">=</span> <span class="n">g2</span><span class="o">.</span><span class="n">sample</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">),</span> <span class="n">concentration_a</span><span class="p">,</span> <span class="n">rate_a</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">ans</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>
<span class="go">(2, 3, 3)</span>
</pre></div>
</div>
<dl class="method">
<dt id="mindspore.nn.probability.distribution.Gamma.concentration">
<em class="property">property </em><code class="sig-name descname">concentration</code><a class="headerlink" href="#mindspore.nn.probability.distribution.Gamma.concentration" title="Permalink to this definition">¶</a></dt>
<dd><p>返回分布的浓度（也称为伽马分布的alpha）。</p>
<p><strong>返回：</strong></p>
<p>Tensor, concentration 的值。</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.nn.probability.distribution.Gamma.rate">
<em class="property">property </em><code class="sig-name descname">rate</code><a class="headerlink" href="#mindspore.nn.probability.distribution.Gamma.rate" title="Permalink to this definition">¶</a></dt>
<dd><p>返回分布的逆尺度（也称为伽马分布的beta）。</p>
<p><strong>返回：</strong></p>
<p>Tensor, rate 的值。</p>
</dd></dl>

</dd></dl>

</div>


           </div>
           
          </div>
          <footer>
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
        <a href="mindspore.nn.probability.distribution.Geometric.html" class="btn btn-neutral float-right" title="mindspore.nn.probability.distribution.Geometric" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
        <a href="mindspore.nn.probability.distribution.Exponential.html" class="btn btn-neutral float-left" title="mindspore.nn.probability.distribution.Exponential" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2021, MindSpore.

    </p>
  </div>
    
    
    
    Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    
    provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>